#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=favicon.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=GUI For Microsoft's ImageX Drive Imaging Tool
#AutoIt3Wrapper_Res_Fileversion=2.0.1.8

#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=John Seekins
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Res_Icon_Add=favicon.ico
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#comments-start
Copyright (c) <2011>, <John Seekins>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#comments-end
#Region Include Statements
#include <GUIConstants.au3>
#include <GuiComboBox.au3>
#include <GuiEdit.au3>
#include <GuiEdit.au3>
;#include <GuiEdit.au3>
#include <ListviewConstants.au3>

#include "Networking.au3"
#include "Imaging.au3"
#include "Partition.au3"
#EndRegion Include Statements

Opt("GUICoordMode", 1)
Opt("TrayIconHide", 1)

#Region Variable Declarations
$programTitle = "RAM Computers Drive Imaging and Restore Tools"
$iniFile = "GUIImageX.ini"
$iniSections = 6
$exclusionListFile = "excludes.ini"
$ImageLoc = IniRead($iniFile, "Global", "ImageLoc", "")
$InstallLoc = IniRead($iniFile, "Global", "InstallLoc", "")
$DriverLoc = IniRead($iniFile, "Global", "DriverLoc", "")
$serverName = "\\" & IniRead($iniFile, "Global", "ServerName", "")
$ImageName = ""
$DestDrive = ""
$cpDrivers = 0
$BaseX = 20
$BaseY = 35

$isNetworkInit = 0
$netOkay = 0

$simpleDiskArray = BasicDiskData()
If $simpleDiskArray <> 0 Then
	Dim $simpleDiskArrayIDs[$simpleDiskArray[0][0] + 1]
	$simpleDiskArrayIDs[0] = $simpleDiskArray[0][0]
Else
	$simpleDiskArrayIDs = 0
EndIf
$detailedDiskArray = 0
$detailedDiskArrayIDs = 0
$selectedDiskID = 0
$lastSelectedDiskID = 0
$selectedPartitionID = 0
$lastSelectedPartitionID = 0
$selectedDisk = 0
$selectedPartition = 0
$partitionCreationSize = 0
$partCreateSliderVal = 0
$partCreateInputVal = 0
$fixedDrivesString = ""

;#cs Determine all fixed drives on computer for capturing or writing images
$fixedDrives = DriveGetDrive("FIXED")
For $i = 1 To $fixedDrives[0]
	$fixedDrives[$i] = StringUpper($fixedDrives[$i])
	If $i > 1 Then $fixedDrivesString &= $fixedDrives[$i] & "|"
Next
$fixedDrivesString = StringTrimRight($fixedDrivesString, 1)
;#ce Determine all fixed drives on computer for capturing or writing images
#EndRegion Variable Declarations

$hGUI = GUICreate($programTitle, 640, 380)

#Region Drop-Down Menu
$fileMenu = GUICtrlCreateMenu("&File")
$iniLoadMenuItem = GUICtrlCreateMenuItem("&Load Ini File", $fileMenu)
$exitProgramMenuItem = GUICtrlCreateMenuItem("E&xit", $fileMenu)
$toolsMenu = GUICtrlCreateMenu("&Tools")
$initNetMenuItem = GUICtrlCreateMenuItem("Initialize Networking...", $toolsMenu)
$checkDiskMenuItem = GUICtrlCreateMenuItem("Test Physical Drives", $toolsMenu)
$helpMenu = GUICtrlCreateMenu("&Help")
$aboutMenuItem = GUICtrlCreateMenuItem("About...", $helpMenu)
#EndRegion Drop-Down Menu

$hGUITab = GUICtrlCreateTab(10, 10, 625, 345)

#Region Create an Image Tab
$hTab_1 = GUICtrlCreateTabItem("Create An Image")

$CurX = $BaseX
$CurY = $BaseY

; File Group
$CurY += 10
GUICtrlCreateGroup("WIM Image", $CurX + 10, $CurY, 580, 155)
$CurY += 18
GUICtrlCreateLabel("Source", $CurX + 20, $CurY + 3)
$hCaptureSourceEdit = GUICtrlCreateCombo($fixedDrives[1], $CurX + 85, $CurY, 300, -1, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, $fixedDrivesString)

$CurY += 27
GUICtrlCreateLabel("Destination", $CurX + 20, $CurY + 3)
$hCaptureDestEdit = GUICtrlCreateInput(IniRead($iniFile, "CAPTURE", "DestName", "initial.wim"), $CurX + 85, $CurY, 300)
$hCaptureDestBrowse = GUICtrlCreateButton("Browse", $CurX + 395, $CurY - 2)

$CurY += 27
GUICtrlCreateLabel("Compression", $CurX + 20, $CurY + 3)
$hCaptureCompression = GUICtrlCreateCombo("", $CurX + 85, $CurY, 100, 500, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "None|Fast|Maximum", IniRead($iniFile, "CAPTURE", "Compression", "None"))

$CurY += 27
GUICtrlCreateLabel("Name", $CurX + 20, $CurY + 3)
$hCaptureNameEdit = GUICtrlCreateInput(IniRead($iniFile, "CAPTURE", "CaptureName", "Image"), $CurX + 85, $CurY, 300)

$CurY += 27
GUICtrlCreateLabel("Description", $CurX + 20, $CurY + 3)
$hCaptureDescEdit = GUICtrlCreateInput(IniRead($iniFile, "CAPTURE", "CaptureDesc", ""), $CurX + 85, $CurY, 300)

; Options Group
$CurY += 40
GUICtrlCreateGroup("Options", $CurX + 10, $CurY, 580, 80)
$CurY += 18

GUICtrlCreateLabel("Exclution List", $CurX + 20, $CurY + 3)
$hCaptureConfigEdit = GUICtrlCreateInput($exclusionListFile, $CurX + 100, $CurY, 300)
$hCaptureConfigBrowseBtn = GUICtrlCreateButton("Browse", $CurX + 410, $CurY - 2)

$CurY += 27
$hCaptureCheckCheck = GUICtrlCreateCheckbox("Verify Image", $CurX + 20, $CurY)
If IniRead($iniFile, "CAPTURE", "CheckImage", "0") = 1 Then GUICtrlSetState($hCaptureCheckCheck, $GUI_CHECKED)

$CurX += 487
$CurY += 47

$hCaptureButtonGo = GUICtrlCreateButton("Capture...", $CurX, $CurY, 100)
#EndRegion Create an Image Tab

#Region Write an Image Tab
$hTab_2 = GUICtrlCreateTabItem("Write an Image")

$CurX = $BaseX
$CurY = $BaseY

; File Group
$CurY += 10
GUICtrlCreateGroup("WIM Image", $CurX + 10, $CurY, 580, 165)
$CurY += 18
GUICtrlCreateLabel("1. Source", $CurX + 20, $CurY + 3)
$hApplySourceEdit = GUICtrlCreateInput(IniRead($iniFile, "APPLY", "Source", "D:\initial.wim"), $CurX + 85, $CurY, 300)
$hApplySourceBrowse = GUICtrlCreateButton("Browse", $CurX + 395, $CurY - 2)
$CurY += 57
GUICtrlCreateLabel("Input Image Number", $CurX + 15, $CurY, 70, 30)
$hApplyName = GUICtrlCreateInput("1", $CurX + 85, $CurY, 40, 20)
GUICtrlSetState($hApplyName, $GUI_DISABLE)
$CurY += 47
GUICtrlCreateLabel("Destination", $CurX + 20, $CurY)
$hApplyDestEdit = GUICtrlCreateCombo($fixedDrives[1], $CurX + 85, $CurY, 300, -1, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, $fixedDrivesString)

; Options Group
$CurY += 60
GUICtrlCreateGroup("Options", $CurX + 10, $CurY, 580, 50)
$CurY += 18
$CurX += 15
$hApplyVerifyCheck = GUICtrlCreateCheckbox("Verify", $CurX, $CurY, 60, 15)
$CurX += 60
$hFormatDrive = GUICtrlCreateCheckbox("Format Drive", $CurX, $CurY, 90, 15)
$CurX += 90
$hWriteBoot = GUICtrlCreateCheckbox("Re-write Boot Sector", $CurX, $CurY, 150, 15)

GUICtrlSetState($hApplyVerifyCheck, $GUI_CHECKED)
If IniRead($iniFile, "APPLY", "Format", "0") = 1 Then GUICtrlSetState($hFormatDrive, $GUI_CHECKED)
If IniRead($iniFile, "APPLY", "WriteBoot", "0") = 1 Then GUICtrlSetState($hWriteBoot, $GUI_CHECKED)

$CurY += 50
$CurX += 330
$hApplyButtonGo = GUICtrlCreateButton("&Apply!", $CurX, $CurY, 100)
#EndRegion Write an Image Tab

#Region Disk Partitioning
$hGUIPartTab = GUICtrlCreateTabItem("Disk Partitioning")

$CurX = $BaseX
$CurY = $BaseY + 10
GUICtrlCreateGroup("Fixed Drives:", $CurX, $CurY, 605, 150)
$CurX += 10
$CurY += 20
$partListViewDisks = GUICtrlCreateListView("Disk Number|Size (MB)|Free Space (MB)", $CurX, $CurY, 250, 100)
If $simpleDiskArray <> 0 Then
	For $i = 1 To $simpleDiskArray[0][0]
		$simpleDiskArrayIDs[$i] = GUICtrlCreateListViewItem($i & "|" & $simpleDiskArray[$i][0] & "|" & $simpleDiskArray[$i][1], $partListViewDisks)
	Next
EndIf
$CurX += 275
$partListViewDetail = GUICtrlCreateListView("Partition #|File System|Size (MB)|Active", $CurX, $CurY, 275, 100, $LVS_SINGLESEL + $LVS_NOSORTHEADER)

$CurX = $BaseX
$CurY += 165
GUICtrlCreateGroup("Partitioning:", $CurX, $CurY, 605, 150)
$CurX += 10
$CurY += 20

;create partition GUI
$partCreateSlider = GUICtrlCreateSlider($CurX, $CurY, 250, 20)
$CurX += 260
$partCreateInput = GUICtrlCreateInput($partitionCreationSize, $CurX, $CurY, 50, 20)
$CurX += 60
GUICtrlCreateLabel("MB", $CurX, $CurY + 5)
$CurX += 60
$partCreateButton = GUICtrlCreateButton("Create Partition", $CurX, $CurY - 2)

;delete and active GUI
$CurY += 50
$CurX = $BaseX + 10
$partDeleteButton = GUICtrlCreateButton("Delete Selected Partition", $CurX, $CurY)
$CurX += 150
$partActiveButton = GUICtrlCreateButton("Mark Selected Partition Active", $CurX, $CurY)
$CurX += 170
$partRescanButton = GUICtrlCreateButton("Rescan Drives", $CurX, $CurY)
#EndRegion Disk Partitioning

#Region Networking and Copying
$hGUINetTab = GUICtrlCreateTabItem("Network and Copying")
$CurX = $BaseX
$CurY = $BaseY + 10
GUICtrlCreateGroup("Pre-built Sysprep Images", $CurX, $CurY, 605, 230)
$CurX += 10
$CurY += 20
$WinXPProOEM = GUICtrlCreateRadio("Windows XP Pro OEM", $CurX, $CurY, 140, 20)
$CurY += 20
$WinXPHomeOEM = GUICtrlCreateRadio("Windows XP Home OEM", $CurX, $CurY, 140, 20)
$CurY += 20
$WinXPVol = GUICtrlCreateRadio("Windows XP Pro Volume License", $CurX, $CurY, 180, 20)
$CurY += 20
$CustomBuild = GUICtrlCreateRadio("Custom Image", $CurX, $CurY, 180, 20)
$CurY += 25
; Options Group
GUICtrlCreateGroup("Options", $CurX, $CurY, 580, 73)
$CurY += 18
$CurX += 15
GUICtrlCreateLabel("Directory to copy files to:  ", $CurX, $CurY)
$CurX += 140
$networkCpDirectory = GUICtrlCreateInput(IniRead($iniFile, "Network", "CopyLocation", "D:\"), $CurX, $CurY - 3)
$CurY += 30
$CurX = $BaseX + 25
$networkCpDrivers = GUICtrlCreateCheckbox("Copy Drivers?", $CurX, $CurY)
$CurX += 110
$networkCpInstall = GUICtrlCreateCheckbox("Copy Program Files?", $CurX, $CurY)
$CurY += 45
$CurX = $BaseX + 8
$cpFilesBtn = GUICtrlCreateButton("  Copy Files  ", $CurX, $CurY)
#EndRegion Networking and Copying

GUISetState()
GUICtrlSetState($networkCpDrivers, $GUI_CHECKED)
GUICtrlSetState($networkCpInstall, $GUI_CHECKED)
GUICtrlSetState($WinXPProOEM, $GUI_DISABLE)
GUICtrlSetState($WinXPHomeOEM, $GUI_DISABLE)
GUICtrlSetState($WinXPVol, $GUI_DISABLE)
GUICtrlSetState($cpFilesBtn, $GUI_DISABLE)

;Hide calling window
modCallingWindow("startnet.cmd", @SW_MINIMIZE)

; Run the GUI until the dialog is closed
Do
	If $netOkay = 1 Then
		$netOkay = 0
		GUICtrlSetState($cpFilesBtn, $GUI_ENABLE)
	EndIf

	#Region Partition Testing Loop
	DisplayDiskInfo()
	If ($selectedDiskID <> 0) And ($simpleDiskArray <> 0) Then
		GUICtrlSetLimit($partCreateSlider, $simpleDiskArray[$selectedDisk][1])
		;		$partCreateInputVal = GUICtrlRead($partCreateInput)
		;		If StringIsDigit($partCreateInputVal) <> 1 Then
		;			$partCreateInputVal = 0
		;		EndIf

		$partCreateSliderVal = GUICtrlRead($partCreateSlider)
		If $partCreateSliderVal <> $partCreateInputVal Then
			$partCreateInputVal = $partCreateSliderVal
			GUICtrlSetData($partCreateInput, $partCreateInputVal)
			$partitionCreationSize = $partCreateInputVal
		EndIf
	EndIf

	$selectedPartitionID = GUICtrlRead($partListViewDetail)
	If ($selectedPartitionID <> 0) And ($selectedPartitionID <> $lastSelectedPartitionID) Then
		$lastSelectedPartitionID = $selectedPartitionID
		$selectedPartition = StringLeft(GUICtrlRead($selectedPartitionID), 1)
	EndIf
	#EndRegion Partition Testing Loop

	$msg = GUIGetMsg()

	Switch $msg
		Case $initNetMenuItem
			If $isNetworkInit = 0 Then
				$isNetworkInit = NetworkInit($serverName, $ImageLoc, $InstallLoc, $DriverLoc)
				If $isNetworkInit = 1 Then $netOkay = 1
			Else
				MsgBox(48, "Warning!", "Networking is already initialized!")
			EndIf

		Case $exitProgramMenuItem
			$msg = $GUI_EVENT_CLOSE

		Case $aboutMenuItem
			MsgBox(0, "RAM Computers ImageX", "Version: " & FileGetVersion("GUIImageX.exe"))

		Case $iniLoadMenuItem
			$iniFile = FileOpenDialog("Select config file", @ScriptDir, "INI files (*.ini)", 1)
			If $iniFile Then
				LoadINIFile()
				If $isNetworkInit = 1 Then NetworkInit($serverName, $ImageLoc, $InstallLoc, $DriverLoc)
			EndIf

		Case $partActiveButton
			If ($selectedDisk <> 0) And ($selectedPartition <> 0) Then
				$test = SetPartitionActive($selectedDisk, $selectedPartition)
				RescanParts()
			Else
				MsgBox(64, "Warning!", "You must select a disk and partition in order to perform this operation...  ")
			EndIf
		Case $partCreateButton
			If ($selectedDisk <> 0) And ($partitionCreationSize <> 0) Then
				$test = CreatePartition($simpleDiskArray, $selectedDisk, $partitionCreationSize & "MB")
				RescanParts()
				#cs Re-writing drive list
					$fixedDrives = DriveGetDrive("FIXED")
					For $i = 1 To $fixedDrives[0]
					$fixedDrives[$i] = StringUpper($fixedDrives[$i])
					If $i > 1 Then $fixedDrivesString &= $fixedDrives[$i] & "|"
					Next
					$fixedDrivesString = StringTrimRight($fixedDrivesString, 1)
					$hCaptureSourceEdit = GUICtrlCreateCombo($fixedDrives[1], $CurX + 85, $CurY, 300, -1, $CBS_DROPDOWNLIST)
					GUICtrlSetData(-1, $fixedDrivesString)
					$hApplyDestEdit = GUICtrlCreateCombo($fixedDrives[1], $CurX + 85, $CurY, 300, -1, $CBS_DROPDOWNLIST)
					GUICtrlSetData(-1, $fixedDrivesString)
				#ce Re-writing drive list
			Else
				MsgBox(64, "Warning!", "You must select a disk and a partition size to perform this operation...  ")
			EndIf
		Case $partDeleteButton
			If ($selectedDisk <> 0) And ($selectedPartition <> 0) Then
				$test = DeletePartition($selectedDisk, $selectedPartition)
				If $test Then RescanParts()
			Else
				MsgBox(64, "Warning!", "You must select a disk and partition in order to perform this operation...  ")
			EndIf
		Case $partRescanButton
			RescanParts()

		Case $cpFilesBtn
			If $isNetworkInit = 1 Then
				Select
					Case GUICtrlRead($WinXPProOEM) = $GUI_CHECKED
						$ImageName = IniRead($iniFile, "XPProOEM", "ImageName", "")
					Case GUICtrlRead($WinXPHomeOEM) = $GUI_CHECKED
						$ImageName = IniRead($iniFile, "XPHomeOEM", "ImageName", "")
					Case GUICtrlRead($WinXPVol) = $GUI_CHECKED
						$ImageName = IniRead($iniFile, "XPVOL", "ImageName", "")
					Case GUICtrlRead($CustomBuild) = $GUI_CHECKED
						$ImageName = FileOpenDialog("Select Source File", $ImageLoc, "WIM Files (*.wim)", 3)
				EndSelect
				If StringCompare($ImageName, "") <> 0 Then
					CopyFiles($ImageName, $InstallLoc, $DriverLoc, GUICtrlRead($networkCpDrivers), GUICtrlRead($networkCpInstall), GUICtrlRead($networkCpDirectory))
				Else
					MsgBox(48, "Invalid Image Name", "An invalid or non-existing image name was input!")
				EndIf
			Else
				MsgBox(48, "Warning!", "Networking must be initialized before copying networked files!")
			EndIf

		Case $checkDiskMenuItem
			MsgBox(64, "Disk Check", "Beginning physical disk testing and repair of all Physical Drives", 5)
			modCallingWindow($programTitle, @SW_MINIMIZE)
			For $i = 1 To $fixedDrives[0]
				$sCmd = @ComSpec & " /c chkdsk " & $fixedDrives[$i] & " /r"
				$ret = RunWait($sCmd, @ScriptDir, @SW_SHOW)
				If $ret <> 1 Then
					SplashTextOn("Return Code", "Disk testing failed with code: " & @error, 400, 200, -1, -1, 32, "Tahoma", 16, 500)
					Sleep(3000)
					SplashOff()
				Else
					MsgBox(64, "Disk Check", "Finished physical disk testing and repair...", 5)
				EndIf
			Next
			modCallingWindow($programTitle, @SW_RESTORE)

		Case $hCaptureButtonGo
			modCallingWindow($programTitle, @SW_MINIMIZE)
			DoCapture(GUICtrlRead($hCaptureSourceEdit), GUICtrlRead($hCaptureDestEdit), GUICtrlRead($hCaptureCompression), GUICtrlRead($hCaptureCheckCheck), _
					GUICtrlRead($hCaptureNameEdit), GUICtrlRead($hCaptureDescEdit), GUICtrlRead($hCaptureConfigEdit))

			modCallingWindow($programTitle, @SW_RESTORE)
			If continueOperations("Image Capture") = 0 Then $msg = $GUI_EVENT_CLOSE

		Case $hCaptureDestBrowse
			$sFile = BrowseForWimToSave(GUICtrlRead($hCaptureDestEdit))
			If $sFile Then GUICtrlSetData($hCaptureDestEdit, $sFile)

		Case $hCaptureConfigBrowseBtn
			$sFile = FileOpenDialog("Select config file", @ScriptDir, "INI files (*.ini)", 1)
			If $sFile Then
				$iniSectionList = IniReadSectionNames($sFile)
				If $iniSectionList[0] = 4 And $iniSectionList[1] = "ExclusionList" Then
					GUICtrlSetData($hCaptureConfigEdit, $sFile)
					$exclusionListFile = $sFile
				Else
					MsgBox(48, "Invalid Exclusion List", "The file you selected does not contain the proper formatting for loading as an exclusion list")
				EndIf
			EndIf

		Case $hApplyButtonGo
			modCallingWindow($programTitle, @SW_MINIMIZE)

			$ret = DoApply(GUICtrlRead($hApplySourceEdit), GUICtrlRead($hApplyDestEdit), GUICtrlRead($hApplyVerifyCheck), GUICtrlRead($hApplyName), _
					GUICtrlRead($hFormatDrive), GUICtrlRead($hWriteBoot))

			modCallingWindow($programTitle, @SW_RESTORE)
			If $ret = 1 Then
				If continueOperations("Applying Image") = 0 Then $msg = $GUI_EVENT_CLOSE
			EndIf

		Case $hApplySourceBrowse
			$sFile = BrowseForWimToLoad(GUICtrlRead($hApplySourceEdit))
			If $sFile Then GUICtrlSetData($hApplySourceEdit, $sFile)
	EndSwitch
Until $msg = $GUI_EVENT_CLOSE

modCallingWindow("startnet.cmd", @SW_RESTORE)
GUIDelete()

#Region General Functions
Func LoadINIFile()
	;determine whether the sections with in the ini file are correct for this particular ini load
	$iniSectionList = IniReadSectionNames($iniFile)
	If $iniSectionList[0] = $iniSections And $iniSectionList[1] = "Global" Then
		$loadINI = MsgBox(1, "Loading INI File...", "This will change all initialized data (including networking data)", 3)
		$ImageLoc = IniRead($iniFile, "Global", "ImageLoc", "")
		$InstallLoc = IniRead($iniFile, "Global", "InstallLoc", "")
		$DriverLoc = IniRead($iniFile, "Global", "DriverLoc", "")
		$serverName = "\\" & IniRead($iniFile, "Global", "ServerName", "")
		GUICtrlSetState($hCaptureDescEdit, IniRead($iniFile, "CAPTURE", "DestName", "initial.wim"))
		GUICtrlSetState($hCaptureCompression, IniRead($iniFile, "CAPTURE", "Compression", "None"))
		GUICtrlSetState($hCaptureNameEdit, IniRead($iniFile, "CAPTURE", "CaptureName", "Image"))
		GUICtrlSetState($hCaptureDescEdit, IniRead($iniFile, "CAPTURE", "CaptureDesc", ""))
		GUICtrlSetState($hApplySourceEdit, IniRead($iniFile, "APPLY", "Source", "D:\initial.wim"))
		If IniRead($iniFile, "CAPTURE", "CheckImage", "0") = 1 Then
			GUICtrlSetState($hCaptureCheckCheck, $GUI_CHECKED)
		Else
			GUICtrlSetState($hCaptureCheckCheck, $GUI_UNCHECKED)
		EndIf
		If IniRead($iniFile, "APPLY", "Format", "0") = 1 Then
			GUICtrlSetState($hFormatDrive, $GUI_CHECKED)
		Else
			GUICtrlSetState($hFormatDrive, $GUI_UNCHECKED)
		EndIf
	Else
		MsgBox(48, "Invalid Program INI File", "The file you selected does not contain the proper formatting for loading as an INI file")
	EndIf
EndFunc   ;==>LoadINIFile

Func IsVisible($handle)
	If BitAND(WinGetState($handle), 2) Then
		Return 1
	Else
		Return 0
	EndIf
EndFunc   ;==>IsVisible

Func modCallingWindow($title, $state)
	Local $activeWindowList = WinList()
	Local $windowNumber = 0
	For $i = 1 To $activeWindowList[0][0]
		If $activeWindowList[$i][0] <> "" And IsVisible($activeWindowList[$i][1]) Then
			Local $windowTitle = StringTrimLeft($activeWindowList[$i][0], StringLen($activeWindowList[$i][0]) - StringLen($title))
			If $windowTitle = $title Then
				$windowNumber = $i
				WinSetState($activeWindowList[$i][0], "", $state)
			EndIf
		EndIf
	Next
EndFunc   ;==>modCallingWindow

Func DisplayDiskInfo()
	$selectedDiskID = GUICtrlRead($partListViewDisks)
	If ($selectedDiskID <> 0) And ($selectedDiskID <> $lastSelectedDiskID) Then
		$lastSelectedDiskID = $selectedDiskID
		If $detailedDiskArrayIDs <> 0 Then
			For $i = 1 To $detailedDiskArrayIDs[0]
				GUICtrlDelete($detailedDiskArrayIDs[$i])
			Next
		EndIf
		$selectedDisk = StringLeft(GUICtrlRead($selectedDiskID), 1)
		$detailedDiskArray = DetailedDiskData($simpleDiskArray, $selectedDisk)
		If $detailedDiskArray <> 0 Then
			Dim $detailedDiskArrayIDs[$detailedDiskArray[0][0] + 1]
			$detailedDiskArrayIDs[0] = $detailedDiskArray[0][0]
			For $i = 1 To $detailedDiskArray[0][0]
				$detailedDiskArrayIDs[$i] = GUICtrlCreateListViewItem($i & "|" & $detailedDiskArray[$i][1] & "|" & $detailedDiskArray[$i][2] & "|" & $detailedDiskArray[$i][0], $partListViewDetail)
			Next
		EndIf
	EndIf
	;_ArrayDisplay($detailedDiskArray)
EndFunc   ;==>DisplayDiskInfo

Func continueOperations($currentOp = "")
	Local $sessionContinue = ""
	If $currentOp <> "" Then MsgBox(64, "Operation Complete", "Completed " & $currentOp)

	$sessionContinue = MsgBox(292, "Continue Session?", "Would you like to perform any further operations?")
	If $sessionContinue = 7 Then
		Return 0
	Else
		Return 1
	EndIf
EndFunc   ;==>continueOperations
#EndRegion General Functions

Func RescanParts()
	If $simpleDiskArrayIDs <> 0 Then
		For $i = 1 To $simpleDiskArrayIDs[0]
			GUICtrlDelete($simpleDiskArrayIDs[$i])
		Next

		$simpleDiskArray = BasicDiskData()
		If $simpleDiskArray <> 0 Then
			Dim $simpleDiskArrayIDs[$simpleDiskArray[0][0] + 1]
			For $i = 1 To $simpleDiskArray[0][0]
				$simpleDiskArrayIDs[$i] = GUICtrlCreateListViewItem($i & "|" & $simpleDiskArray[$i][0] & "|" & $simpleDiskArray[$i][1], $partListViewDisks)
			Next
		EndIf
		If $detailedDiskArrayIDs <> 0 Then
			For $i = 1 To $detailedDiskArrayIDs[0]
				GUICtrlDelete($detailedDiskArrayIDs[$i])
			Next
		EndIf
	EndIf
EndFunc   ;==>RescanParts
#EndRegion
